<template>
  <base-breadcrumb :title="$route.meta.title">
    <!-- 组织架构编辑 -->

    <a-spin :spinning="loading">
      <a-form-model
        ref="ruleForm"
        :model="form"
        :label-col="{ span: 6 }"
        :wrapper-col="{ span: 18 }"
        :rules="editModel != 0 ? rules : {}"
      >
        <!-- 表单 -->
        <a-card :bordered="false">
          <title-name title="基本信息" />

          <custom-form
            :form-list="formList"
            :form="form"
            :edit-model="editModel == 0 ? '' : ''"
          />
          <!-- </a-form-model> -->
        </a-card>
      </a-form-model>
    </a-spin>
    <!-- 页脚操作栏 -->
    <div class="tool-btns page-btn-right-top">
      <a-button
        v-if="editModel != 0"
        :loading="loading"
        type="primary"
        class="button_right ml20"
        @click="handleSubmit"
      >
        提交
      </a-button>
      <a-button
        class="ml20"
        type="primary"
        @click="handleClose"
      >
        关闭
      </a-button>
    </div>
  </base-breadcrumb>
</template>

<script>
import { getUnionEmployeeById, updateByPrimaryKeySelective } from '@/api/union/organizationManagement' // api
import BaseEditPage from '@/views/baseEditPage' // 编辑详情页基础配置
import TreeSelectOrganization from '@/components/TreeSelectOrganization'
import Selector from '@/components/Select/Selector'
import SelectPersonByProject from '@/components/Select/SelectPersonByProject'

export default {
    name:'a'+Date.now(),
    extends: new BaseEditPage(),
    components: {
    },
    data() {
        return {
            loading: false, // 加载控件
            editModel: 0, // 操作状态:0 查看;1 编辑;2 新增
            form: {},
            rules: {
                unionPost: [{ required: true, message: '请选择职位', trigger: 'change' }],
            }, // 校验规则
            init: false, // 初始化控件
            formCode: '', // 形式选中项code
        }
    },
    watch: {},
    mounted() {
        let userInfo = JSON.parse(sessionStorage.getItem('ycloud-user_info'))
        this.form.orgDeptName =
            (userInfo.currentPost.code === 'PD' ? userInfo.currentPost.orgName + '-' : '') + userInfo.currentPost.name
        this.form.orgDeptId = userInfo.currentPost.id
        this.$route.meta.title = ['会员查看', '会员编辑', '会员新增'][this.editModel]
        // 不为添加时请求详情
        if (this.editModel != 2) {
            this.loading = true
            getUnionEmployeeById(this.id)
                .then((res) => {
                    this.loading = false
                    res.data.unionPost = res.data.unionPost || []
                    if (res.data.sex == '0') {
                        res.data.sex = '女'
                    } else if (res.data.sex == '1') {
                        res.data.sex = '男'
                    }
                    res.data.postPNames = res.data.postPNames.join(',')
                    this.form = res.data

                    this.$nextTick(() => {
                        this.init = true
                    })
                })
                .catch(() => {
                    this.loading = false
                })
        } else {
            this.$nextTick(() => {
                this.init = true
            })
        }
    },
    computed: {
        formList() {
            return [
                {
                    keyName: 'name',
                    type: 'BaseInput',
                    disabled: true,

                    label: '姓名',
                },
                {
                    keyName: 'jobNum',
                    type: 'BaseInput',
                    disabled: true,

                    label: '员工工号',
                },
                {
                    keyName: 'unionOrgStr',
                    type: 'BaseInput',

                    disabled: true,
                    label: '工会组织',
                },
                {
                    keyName: 'idCard',
                    type: 'BaseInput',

                    disabled: true,
                    label: '身份证号码',
                },
                {
                    keyName: 'mz',
                    type: 'BaseInput',

                    disabled: true,
                    label: '民族',
                },
                {
                    keyName: 'sex',
                    type: 'BaseInput',

                    disabled: true,
                    label: '性别',
                },
                {
                    keyName: 'birthday',
                    type: 'BaseInput',

                    disabled: true,
                    label: '出生日期',
                },
                //
                {
                    keyName: 'nativePlace',
                    type: 'BaseInput',

                    disabled: true,
                    label: '籍贯',
                },
                //
                {
                    keyName: 'joinWorkDate',
                    type: 'BaseInput',

                    disabled: true,
                    label: '参加工作时间',
                },
                //
                {
                    keyName: 'postPNames',
                    type: 'BaseInput',

                    disabled: true,
                    label: '工作职务',
                },
                //
                {
                    keyName: 'politicsStatus',
                    type: 'BaseInput',

                    disabled: true,
                    label: '政治面貌',
                },
                //
                {
                    keyName: 'partyTime',
                    type: 'BaseInput',

                    disabled: true,
                    label: '入党时间',
                },
                {
                    keyName: 'phoneNum',
                    type: 'BaseInput',

                    disabled: true,
                    label: '手机号码',
                },
                {
                    keyName: 'specialitieMax',
                    type: 'BaseInput',

                    disabled: true,
                    label: '最高学历',
                },
                {
                    keyName: 'specialitie',
                    type: 'BaseInput',

                    disabled: true,
                    label: '所学专业',
                },
                {
                    keyName: 'jobTitle',
                    type: 'BaseInput',

                    disabled: true,
                    label: '职称',
                },
                {
                    keyName: 'unionPost',
                    disabled: this.editModel == 0,
                    label: '工会职务',
                    type: Selector,
                    span: 24,
                    attrs: {
                        urlType: 'union',
                        mode: 'multiple',
                        isGroup: true,
                        apiSuffix: 'queryUnionPost',
                    },
                },
                {
                    keyName: 'remarks',
                    type: 'BaseTextarea',
                    disabled: this.editModel == 0,
                    span: 24,
                    label: '备注',
                },
            ]
        },
    },
    methods: {
        /**
         * 提交表单
         */
        handleSubmit() {
            let that = this
            let api = [updateByPrimaryKeySelective][that.editModel - 1] // 根据操作切换url地址
            // 校验表单
            that.$refs.ruleForm.validate((e) => {
                if (e) {
                    // 提交表单
                    that.loading = true
                    let form = that.$clone(that.form)
                    api(form)
                        .then(() => {
                            that.loading = false
                            that.$message.success('提交成功！')
                            that.$multiTab.close()
                        })
                        .catch(() => {
                            that.loading = false
                        })
                }
            })
        },
        handleClose() {
            if (this.isAudit) {
                window.close()
            } else {
                this.$multiTab.close(this.$route.fullpath)
            }
        },
    },
}
</script>

<style lang="less" scoped>

.file_prompt {
    color: #999;
}
</style>